using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JGSY.CMS.LowCode.Platform.Domain.Entities.Base;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities
{
    /// <summary>
    /// 分类管理实体
    /// 用于管理文章、产品等内容的分类，支持层级结构，支持多租户隔离
    /// </summary>
    [Table("categories")]
    public class Category : AuditableEntity, ITenantEntity
    {
        /// <summary>
        /// 租户ID
        /// 用于多租户数据隔离
        /// </summary>
        [Required]
        [StringLength(36)]
        public string TenantId { get; set; } = string.Empty;

        /// <summary>
        /// 分类名称
        /// </summary>
        [Required]
        [StringLength(255)]
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 分类别名/URL
        /// </summary>
        [Required]
        [StringLength(255)]
        public string Slug { get; set; } = string.Empty;

        /// <summary>
        /// 分类类型
        /// article=文章分类, product=产品分类
        /// </summary>
        [Required]
        [StringLength(50)]
        public string Type { get; set; } = string.Empty;

        /// <summary>
        /// 父分类ID（层级结构）
        /// </summary>
        public long? ParentId { get; set; }

        /// <summary>
        /// 分类描述
        /// </summary>
        [Column(TypeName = "text")]
        public string? Description { get; set; }

        /// <summary>
        /// 分类图片URL
        /// </summary>
        [StringLength(255)]
        public string? ImageUrl { get; set; }

        /// <summary>
        /// 排序权重
        /// </summary>
        public int SortOrder { get; set; } = 0;

        /// <summary>
        /// 状态（启用/禁用）
        /// 0=禁用, 1=启用
        /// </summary>
        public byte Status { get; set; } = 1;

        /// <summary>
        /// SEO标题
        /// </summary>
        [StringLength(255)]
        public string? SeoTitle { get; set; }

        /// <summary>
        /// SEO关键词
        /// </summary>
        [StringLength(500)]
        public string? SeoKeywords { get; set; }

        /// <summary>
        /// SEO描述
        /// </summary>
        [StringLength(500)]
        public string? SeoDescription { get; set; }

        /// <summary>
        /// 标签列表（JSON格式）
        /// </summary>
        [Column(TypeName = "json")]
        public string? Tags { get; set; }

        // 导航属性

        /// <summary>
        /// 租户导航属性
        /// </summary>
        public Tenant? Tenant { get; set; }

        /// <summary>
        /// 父分类导航属性
        /// </summary>
        [ForeignKey(nameof(ParentId))]
        public Category? Parent { get; set; }

        /// <summary>
        /// 子分类集合
        /// </summary>
        [InverseProperty(nameof(Parent))]
        public ICollection<Category> Children { get; set; } = new List<Category>();

        // 该分类下的文章集合（如果是文章分类）
        //[InverseProperty(nameof(Article.CategoryId))]
        //public ICollection<Article> Articles { get; set; } = new List<Article>();

        // 该分类下的产品集合（如果是产品分类）
        //[InverseProperty(nameof(Product.CategoryId))]
        //public ICollection<Product> Products { get; set; } = new List<Product>();
    }
}
